/* eslint-disable import/no-extraneous-dependencies */
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
const { override, fixBabelImports, addWebpackAlias, overrideDevServer } = require('customize-cra');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');

const draw = 'node_modules/@jkyu/monet-draw/build';
// override
module.exports = {
  webpack: override(
    addWebpackAlias({
      static: path.resolve(__dirname, './static'),
    }),
    // 针对antd 实现按需打包：根据import来打包 (使用babel-plugin-import)
    fixBabelImports('import', {
      libraryName: 'antd',
      libraryDirectory: 'es',
      style: 'css', // 自动打包相关的样式 默认为 style:'css'
    }),
    (config) => {
      config.resolve.plugins = config.resolve.plugins.filter((plugin) => !(plugin instanceof ModuleScopePlugin));
      config.plugins.push(
        new CopyPlugin([
          {
            from: path.join(draw, 'static'),
            to: 'static',
          },
        ])
      );
      return config;
    }
  ),
  devServer: overrideDevServer((config) => ({
    ...config,
    hot: false,
  })),
};
